<template>
    <FormItem :label="Config.Label + ' :'" class="FormItem">
        <Select transfer v-model="itemValue" :disabled="Config.disable" size="small">
            <Option v-for="select in selectValue" :value="select.DM" :key="select.DM">{{ select.MC }}</Option>
        </Select>
    </FormItem>
</template>

<script>
import Dist from './dist'

export default {
    props: ['value', 'Config'],
    data() {
        return {
            itemValue: null,
            selectValue: []
        }
    },
    mounted() {
        this.selectValue = Dist[this.Config.DicCode]
        this.$nextTick(() => {
            // 特殊类型判断
            if (this.Config.ParentKey == 'TranRevList' && this.Config.ParamKey == 'IsER') {
                this.itemValue = this.value.TranRevList[0].IsER
            } else if (this.Config.ParentKey == 'TranRevList' && this.Config.ParamKey == 'AntType') {
                this.itemValue = this.value.TranRevList[0].AntType
            } else {
                // 正常类型
                this.itemValue = this.value[this.Config.ParentKey][this.Config.ParamKey]
            }
            if (this.Config.ParamKey == 'FreqType') {
                this.$emit('ChangeFreqType', this.Config, this.value)
            }
        })
    },
    watch: {
        itemValue(val) {
            // 特殊类型赋值
            if (this.Config.ParentKey == 'TranRevList' && this.Config.ParamKey == 'IsER') {
                this.value.TranRevList[0].IsER = val
            } else if (this.Config.ParentKey == 'TranRevList' && this.Config.ParamKey == 'AntType') {
                this.value.TranRevList[0].AntType = val
            } else {
                // 正常类型
                this.value[this.Config.ParentKey][this.Config.ParamKey] = val
            }
            if (this.Config.ParamKey == 'FreqType') {
                this.$emit('ChangeFreqType', this.Config, this.value)
            }
        }
    }
}
</script>

<style lang="less" scoped>
.FormItem {
    margin: 0.5rem 0;
    /deep/.ivu-form-item-label {
        padding-top: 5px;
        padding-bottom: 5px;
    }
}
.FormBox {
    padding: 0.3rem 0;
    display: flex;
}
.Unit {
    padding-left: 0.5rem;
}
</style>